﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TicketReservationSystemDataLayer;

namespace WpfApplicationEventsManager
{
    /// <summary>
    /// Interaction logic for AddEditEventsWindow.xaml
    /// </summary>
    public partial class AddEditEventsWindow : Window
    {
        TicketReservationSystemDataContext context;
        private bool save;

        public Location Location
        {
            get { return (Location)this.comboBoxLocation.SelectedItem; }
            set
            {
                context = new TicketReservationSystemDataContext();
                this.comboBoxLocation.ItemsSource = LocationDAO.GetAllLocations(context);
                this.comboBoxLocation.SelectedValuePath = "Id";
                this.comboBoxLocation.SelectedValue = value.Id; 
            }
        }

        public Category Category
        {
            get { return (Category)this.comboBoxCategory.SelectedItem; }
            set
            {
                context = new TicketReservationSystemDataContext();
                this.comboBoxCategory.ItemsSource = CategoryDAO.GetAllCategories(context);
                comboBoxCategory.SelectedValuePath = "Id";
                comboBoxCategory.SelectedValue = value.Id;
            }
        }

        public bool Save
        {
            get { return this.save; }
        }

        public AddEditEventsWindow()
        {
            InitializeComponent();
        }


        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            this.save = true;
            this.Close();
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.save = false;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.Title == "Add Event")
            {
                context = new TicketReservationSystemDataContext();
                this.comboBoxCategory.ItemsSource = CategoryDAO.GetAllCategories(context);
                this.comboBoxLocation.ItemsSource = LocationDAO.GetAllLocations(context);
            }
        }
    }
}
